/**
 * 初始化数据源定义详情对话框
 */
var SdcMedicalGroupInfoDlg = {
    id: "SdcMedicalGroupTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    zTree: null,
    layerIndex: -1,
    linkFlag: false,
    SdcMedicalGroupData:  {},			//字典
    validateFields: {
        entityId: {
            validators: {
                notEmpty: {
                    message: '选择病种不能为空'
                }
            }
        },
        reason: {
            validators: {
                notEmpty: {
                    message: '依据原因不能为空'
                }
            }
        }
    }
};

SdcMedicalGroupInfoDlg.close = function() {
    parent.layer.close(parent.layer.getFrameIndex(window.name)); //先得到当前iframe层的索引,再执行关闭
}

/**
 * 验证数据是否为空
 */
SdcMedicalGroupInfoDlg.validate = function () {
    $('#sdcMedicalGroupInfoForm').data("bootstrapValidator").resetForm();
    $('#sdcMedicalGroupInfoForm').bootstrapValidator('validate');
    return $("#sdcMedicalGroupInfoForm").data('bootstrapValidator').isValid();
}

/**
 * 提交新增
 */
SdcMedicalGroupInfoDlg.addSubmit = function() {

    if (!this.validate()) {
        return;
    }
    //提交信息
    Sys.ajaxForm('sdcMedicalGroupInfoForm',Sys.backendPath + "/sdc/case/add",function(res) {
        Sys.success(res.message);
        parent.postMessage("save","*");
        SdcMedicalGroupInfoDlg.close();
    });
}

SdcMedicalGroupInfoDlg.entityChange = function(source) {
    var sourceId = source.value;
    $('#reason').combobox("clear");
    //根据父级机构 查询子机构
    var ajax = new $ax(Sys.backendPath + "/sds/sdsmedicalgroup/getReasonByEntityId", function(res){
        var reasonMap = $.parseJSON(res);
        $('#reason').combobox({
            data: reasonMap,
            valueField:'value',
            textField:'text',
            onLoadSuccess: function () {
                $(this).combobox("setValue", "");
            }
        });
    },function(data){
        Sys.error("查询失败!" + data.responseJSON.message + "!");
    });
    ajax.set({"entityId":sourceId});
    ajax.setAsync(false);
    ajax.start();
}

$(function() {
    Sys.initValidator("sdcMedicalGroupInfoForm", SdcMedicalGroupInfoDlg.validateFields);
});
